package com.atfcm.stack;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author 96534
 * @create 2025/3/21 13:45
 */

class MyQueue {
    Deque<Integer> stack = new LinkedList<>();
    Deque<Integer> stack2 = new LinkedList<>();

    public MyQueue() {
    }

    public void push(int x) {
        stack.push(x);
    }

    public int pop() {
        if (stack2.isEmpty()) {
            while (!stack.isEmpty()) {
                stack2.push(stack.pop());
            }
            return stack2.pop();
        } else {
            return stack2.pop();
        }
    }

    public int peek() {
        if (stack2.isEmpty()) {
            while (!stack.isEmpty()) {
                stack2.push(stack.pop());
            }
        }
        return stack2.peek();
    }

    public boolean empty() {
        return stack.isEmpty() && stack2.isEmpty();
    }
}

public class T_232_用栈实现队列 {
}
